package com.css.fxfzaqbz.modules.data.service.impl;

import com.css.fxfzaqbz.modules.data.entity.Expert;
import com.css.fxfzaqbz.modules.data.entity.Report;
import com.css.fxfzaqbz.modules.data.repository.ExpertRepository;
import com.css.fxfzaqbz.modules.data.repository.ReportRepository;
import com.css.fxfzaqbz.modules.data.service.ExpertService;
import com.css.fxfzaqbz.util.CreateGson;
import com.css.fxfzaqbz.util.PlatformDateUtils;
import com.css.fxfzaqbz.util.PlatformSessionUtils;
import com.css.fxfzaqbz.util.UUIDGenerator;
import com.css.fxfzaqbz.zcpt.sys.entity.SUser;
import com.css.fxfzaqbz.zcpt.sys.service.SUserService;
import com.google.gson.JsonObject;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ExpertServiceImpl implements ExpertService {

    @Resource
    ExpertRepository expertRepository;
    @Resource
    ReportRepository reportRepository;

    @Override
    public Report saveExpert(List<Expert> experts) {
        StringBuilder stringBuilder = new StringBuilder("");
        for (Expert expert : experts) {
            expert.setId(UUIDGenerator.getUUID());
            expert.setStatus("1");
            stringBuilder.append(",").append(expert.getZjName());
            expertRepository.saveExpert(expert);
        }
        String substring = stringBuilder.toString().substring(1);
        String srId = experts.get(0).getSrId();
        Report report = reportRepository.getReportById(srId);
        report.setPingStatus("1");
        report.setPingJia(substring);
        reportRepository.updateZiStatus(report);
        return report;
    }

    @Override
    public void updateExpert(Expert expert) {
        expert.setPsTime(PlatformDateUtils.getCurrentSqlDate());
        expert.setStatus("2");
        expertRepository.updateExpert(expert);
        Expert expert1=expertRepository.getById(expert.getId());
        String srId = expert1.getSrId();
        List<Expert> experts = expertRepository.getAllExpertBySrId(srId);
        Boolean flag = true;
        for (Expert expert2 : experts) {
            if (!expert2.getStatus().equals("2")) {
                flag = false;
            }
        }
        if (flag){
            reportRepository.updatePsStatus("2",srId);
        }

    }


}
